package ontology.models.contract;

import java.util.Date;

import jade.content.Concept;
import jade.content.Predicate;


public abstract class AbstractSituation implements Concept, Comparable<AbstractSituation> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String when;
	private String contractId;
	private ActionP action;
	
	public ActionP getAction() {
		return action;
	}
	public void setAction(ActionP action) {
		this.action = action;
	}
	public String getWhen() {
		return when;
	}
	public void setWhen(String when) {
		this.when = when;
	}
	public String getContractId() {
		return contractId;
	}
	public void setContractId(String contractId) {
		this.contractId = contractId;
	}
	@Override
	public String toString() {
		Date when = new Date(Long.parseLong(this.when));
		return "[action=" + action.toString() + ", when=" + when.toString() + ", contractId="+contractId+"]";
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((action == null) ? 0 : action.hashCode());
		result = prime * result
				+ ((contractId == null) ? 0 : contractId.hashCode());
		result = prime * result + ((when == null) ? 0 : when.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractSituation other = (AbstractSituation) obj;
		if (action == null) {
			if (other.action != null)
				return false;
		} else if (!action.equals(other.action))
			return false;
		if (contractId == null) {
			if (other.contractId != null)
				return false;
		} else if (!contractId.equals(other.contractId))
			return false;
		if (when == null) {
			if (other.when != null)
				return false;
		} else if (!when.equals(other.when))
			return false;
		return true;
	}
	
	public int compareTo(AbstractSituation element){
		long when = Long.parseLong(this.when);
		long elementWhen = Long.parseLong(element.getWhen());
		if(when < elementWhen)
			return -1;
		if(when == elementWhen)
			return 1;
		else return 1;
	}
	
}
